﻿using System;
using System.Windows.Data;
using System.Windows.Media;

namespace Examples.Converters
{
    public class EventTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var color = Colors.Transparent;
            byte opacity = 255;

            if (parameter != null)
                opacity = byte.Parse(parameter.ToString());

            if (value.ToString().Contains("InformationEvent"))
                color = Color.FromArgb(opacity, 71,155,157);
            else if (value.ToString().Contains("ClientErrorEvent"))
                color = Color.FromArgb(opacity, 239, 90, 54);
            else if (value.ToString().Contains("ErrorEvent"))
                color = Color.FromArgb(opacity, 216, 55, 16);
            else if (value.ToString().Contains("WarningEvent"))
                color = Color.FromArgb(opacity, 190, 191, 63);
            else
                color = Color.FromArgb(opacity, 110, 110, 110);

            return new SolidColorBrush(color);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}